package com.juc.forkJoin.forkJoin6;

import java.util.concurrent.RecursiveTask;

import com.juc.forkJoin.forkJoin2.MyRecursiveAction;

@SuppressWarnings("serial")
public class MyRecursiveTask extends RecursiveTask<String>{
	private int beginValue;
	private int endValue;
	
	public MyRecursiveTask(int beginValue,int endValue) {
		this.beginValue = beginValue;
		this.endValue = endValue;
	}
	@Override
	protected String compute() {
		System.out.println(Thread.currentThread().getName() + "  --------------");
		if(endValue - beginValue > 2) {
			int middelNum = (endValue + beginValue) / 2;
			MyRecursiveTask leftTask = new MyRecursiveTask(beginValue, middelNum);
			MyRecursiveTask rightTask = new MyRecursiveTask(middelNum +1, endValue);
			this.invokeAll(leftTask, rightTask);
			return leftTask.join() + rightTask.join();
		}else {
			String returnString = "";
			for (int i = beginValue; i <= endValue; i++) {
				returnString = returnString + (i);
			}
			System.out.println(" else 返回： " + returnString + "   " + beginValue  + "  " + endValue);
		    return returnString;
		}
		
	}

}
